﻿using Microsoft.Practices.Prism.Commands;
using Microsoft.Practices.Prism.Events;
using Microsoft.Practices.Prism.ViewModel;
using Microsoft.Practices.ServiceLocation;
using Microsoft.Practices.Unity;
using System.Windows;
using UI.Core.Events;

namespace UI.Module.Menu
{
    public class MenuViewModel : NotificationObject
    {
        public readonly IEventAggregator EventAggregator;
        public IUnityContainer Container { get; set; }
        public string ActiveWorkspace { get; set; }

        public MenuViewModel()
        {
            EventAggregator = ServiceLocator.Current.GetInstance<IEventAggregator>();
            _exitCommand = new DelegateCommand(OnExit, CanExit);

            _openUsersCommand = new DelegateCommand(OnOpenUsers, CanOpenUsers);
            _openProfilsCommand = new DelegateCommand(OnOpenProfils, CanOpenProfils);
        }
        
        public DelegateCommand OpenUsersCommand { get { return _openUsersCommand; } }
        private readonly DelegateCommand _openUsersCommand;
        private bool CanOpenUsers()
        {
            return true;
        }
        private void OnOpenUsers()
        {
            EventAggregator.GetEvent<ViewRequestedEvent>().Publish("UsersView");
        }

        public DelegateCommand OpenProfilsCommand { get { return _openProfilsCommand; } }
        private readonly DelegateCommand _openProfilsCommand;
        private bool CanOpenProfils()
        {
            return true;
        }
        private void OnOpenProfils()
        {
            EventAggregator.GetEvent<ViewRequestedEvent>().Publish("ProfilsView");
        }

        public DelegateCommand ExitCommand { get { return _exitCommand; } }
        private readonly DelegateCommand _exitCommand;
        private bool CanExit()
        {
            return true;
        }
        private void OnExit()
        {
            Application.Current.Shutdown();
        }
    }
}
